package com.tqz.zookeeper.queue.springboot;

import cn.hutool.json.JSONUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * 模拟下单接口.
 *
 * @author <a href="https://github.com/tian-qingzhao">tianqingzhao</a>
 * @since 2025/9/5 19:54
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    private static final int count = 1000;

    @RequestMapping("/create")
    public String createOrder() {
        // 模拟下单
        for (int i = 0; i < count; i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("orderId", UUID.randomUUID().toString());
            map.put("price", count * i);
            map.put("dataTime", new Date());
            map.put("seq", i);

            // 订单对象存入队列
            ZKQueueUtils.setQueueData(JSONUtil.toJsonStr(map));
        }
        return "success";
    }
}
